
local M={}

-- 填充路--》参数,起始位置，路类型list，玩家对象，关卡id
function M.FullRoad(startCframe,list,player,levelId,parent)
    local modelInsts = {}
    local connections = {}
    for index, id in pairs(list) do
        -- local model = _G.CommonOHOH:GetPath_Loop(id,game.ReplicatedStorage.Resource)
        local model = _G.CommonOHOH:GetPath_Loop("testPart",game.ReplicatedStorage.Resource)
        modelInsts[index] =model:Clone()
        modelInsts[index].Parent = parent
        modelInsts[index].Name = player.user_id
        modelInsts[index].ctrl.model.value.CanCollide = true
        modelInsts[index].ctrl.model.value.Transparency = 1
        if index == 1 then
            modelInsts[index].PrimaryPart.CFrame = startCframe
        else
            modelInsts[index].PrimaryPart.CFrame =  modelInsts[index-1].ctrl.nextPos.value.WorldCFrame
        end
        connections[index] = modelInsts[index].ctrl.model.value.Touched:Connect(function(hit)
            local hitPlayer = game.Players:GetPlayerFromCharacter(hit.parent)
            if hitPlayer then
                if hitPlayer.UserId ==player.user_id  then
                    connections[index]:Disconnect()
                    if modelInsts[index] then
                        modelInsts[index].ctrl.model.value.Transparency = 0
                        player.attribute.ActivatedRoadSum = player.attribute.ActivatedRoadSum+1
                    end
                    -- modelInsts[index].ctrl.model.value.Transparency = 0
                    -- player.attribute.ActivatedRoadSum = player.attribute.ActivatedRoadSum+1
                end
            end
        end)
    end
    return modelInsts[#list].ctrl.nextPos.value.WorldCFrame
end


return M